package threaddemo;

public class SequenceNumber {

	private static ThreadLocal<Integer> seqNum=new ThreadLocal<Integer>(){
		public Integer initialValue(){
			
			return 0;
		}
	};
	
	public int getNext(){
		seqNum.set(seqNum.get()+1);
		return seqNum.get();
	}
	
	public static void main(String[] args) {
		SequenceNumber seqNumber=new SequenceNumber();
		new TestThread(seqNumber).start();
		new TestThread(seqNumber).start();
		new TestThread(seqNumber).start();
	}
	
	
}

class TestThread extends Thread{
	private SequenceNumber seqNumber;
	
	public SequenceNumber getSeqNumber() {
		return seqNumber;
	}

	public void setSeqNumber(SequenceNumber seqNumber) {
		this.seqNumber = seqNumber;
	}

	public TestThread(SequenceNumber seqNumber) {
		super();
		this.seqNumber = seqNumber;
	}

	public void run(){
		for (int i = 0; i < 3; i++) {
			System.out.println(Thread.currentThread().getName()+":"+seqNumber.getNext());
		}
	}
}